#import <UIKit/UIKit.h>
#import "BLEDevice.h"
#import "FSDevice.h"

//系统应用指令
typedef NS_ENUM(int, TreadmillCommand) {
    TREADMILL_INFO			= 0x50,		//读取系统信息
    TREADMILL_STATE			,			//读取系统状态
    TREADMILL_DATA			,			//读取系统数据
    TREADMILL_CONTROL		,			//控制系统
};

//系统信息(读取)
typedef NS_ENUM(int, TreadmillInfo) {
    TREADMILL_INFO_MODEL		= 0,	//返回机型 (厂家代码/机型代码)
    TREADMILL_INFO_DATE			,		//出厂日期 (年/月/日)
    TREADMILL_INFO_SPEED		,		//速度参数 (最高速度/最低速度/系统单位)
    TREADMILL_INFO_INCLINE		,		//坡度参数 (最高坡度/水平坡度)
    TREADMILL_INFO_DISTANCE		,		//累计里程 (0.1km)
};

//系统状态(发送状态指令后,设备将返回以下状态及数据)
typedef NS_ENUM(int, TreadmillState) {
    TREADMILL_STATE_NORMAL		= 0,	//常规等待运行
    TREADMILL_STATE_END			,		//结束运行 (数据同运行数据)
    TREADMILL_STATE_START		,		//启动过程 (启动倒计值)
    TREADMILL_STATE_RUNNING		,		//运行数据 (速度/坡度/时间/距离/热量/步数/心率)
    TREADMILL_STATE_STOP		,		//停止运行 (数据同运行数据)
    
    TREADMILL_STATE_ERROR		,		//系统故障 (故障代码)
    TREADMILL_STATE_SAFETY		,		//安全锁定
    TREADMILL_STATE_SLEEP		,		//睡眠中
};

//系统数据
typedef NS_ENUM(int, TreadmillData) {
    TREADMILL_DATA_SPORT		= 0,	//运动数据 (时间/距离/热量/步数)
    TREADMILL_DATA_INFO			,		//运动信息 (用户ID/运动ID/模式/倒计值)
    TREADMILL_DATA_SPEED		,		//速度数据 ()
    TREADMILL_DATA_INCLINE		,		//坡度数据 ()
};

//系统控制(写入)
typedef NS_ENUM(int, TreadmillCotrol) {
    TREADMILL_CONTROL_USER		= 0,	//用户数据 (用户ID/体重/身高)
    TREADMILL_CONTROL_START		,		//开始启动 (赛事ID/模式/段数/倒计值)  返回:启动倒计值
    TREADMILL_CONTROL_RUN		,		//运行数据 (实际目标速度/坡度)
    TREADMILL_CONTROL_STOP		,		//停止运行
    TREADMILL_PROGRAM_SPEED		,		//速度程式数据
    TREADMILL_PROGRAM_INCLINE	,		//坡度程式数据
};

//系统模式
typedef NS_ENUM(NSInteger, TreadmillMode) {
    TREADMILL_MODE_NORMAL		= 0,	//常规模式（自由模式）
    TREADMILL_MODE_TIMER		,		//倒计时间模式
    TREADMILL_MODE_DISTANCE		,		//倒计距离模式
    TREADMILL_MODE_CALORIES		,		//倒计卡路里模式
    TREADMILL_MODE_STEPS		,		//倒计步数模式
    TREADMILL_MODE_PROGRAM		,		//程式模式
    TREADMILL_MODE_MATCH		,		//赛事模式
    TREADMILL_MODE_HRC			,		//心率控速模式
	TREADMILL_MODE_OTHER		,		//其它模式
};

typedef NS_ENUM(NSInteger, TreadmillError) {
	TREADMILL_ERROR_E00			= 1,
	TREADMILL_ERROR_E01			,
	TREADMILL_ERROR_E02			,
	TREADMILL_ERROR_E03			,
	TREADMILL_ERROR_E04			,
	TREADMILL_ERROR_E05			,
	TREADMILL_ERROR_E06			,
	TREADMILL_ERROR_E07			,
	TREADMILL_ERROR_E08			,
	TREADMILL_ERROR_E09			,
	TREADMILL_ERROR_E10			,
	TREADMILL_ERROR_E11			,
	TREADMILL_ERROR_E12			,
	
	TREADMILL_ERROR_SAFE		= 20,	//安全锁开启
};

typedef NS_ENUM(NSInteger, TreadmillStartError) {
	TREADMILL_START_ERROR			= 1,	//系统错误 (见 TreadmillError)
	TREADMILL_START_ERROR_SLEEP		,		//睡眠中
	TREADMILL_START_ERROR_RUNNING	,		//已运行
	TREADMILL_START_ERROR_TIMEOUT	,		//通讯超时
};

typedef struct {
    uint    count;          //程式段数
    
    Byte    speed[128];     //目标速度
    Byte    incline[128];   //目标坡度
    UInt16  time[128];      //目标时长(秒)
} TreadmillProgram;

//设备参数 ===============================================
@interface TreadmillParam : NSObject

@property (nonatomic, readonly) NSInteger	unit;				//速度单位(0:公 1:英)
@property (nonatomic, readonly) CGFloat		distance;			//累计里程(km)
@property (nonatomic, readonly) CGFloat		maxSpeed;			//最大速度
@property (nonatomic, readonly) CGFloat		minSpeed;			//最小速度
@property (nonatomic, readonly) NSInteger	maxIncline;			//最大坡度
@property (nonatomic, readonly) NSInteger	minIncline;			//最小坡度

@end


//体脂秤 ================================================
@interface BLEScales : NSObject

@property (nonatomic, readonly) CGFloat		weight;				//体重 kg
@property (nonatomic, readonly) CGFloat		fat;				//体脂率
@property (nonatomic, readonly) CGFloat		visceral;			//内脏脂肪
@property (nonatomic, readonly) CGFloat		bone;				//骨量
@property (nonatomic, readonly) CGFloat		water;				//水分
@property (nonatomic, readonly) CGFloat		metabolism;			//基础代谢
@property (nonatomic, readonly) CGFloat		bmi;				//BMI
@property (nonatomic, readonly) CGFloat		muscle;				//肌肉

@end

//跑步机类 ===============================================
@interface BLETreadmill : FSBLEDevice

@property (nonatomic, readonly) TreadmillParam		*param;		//跑步机参数
@property (nonatomic, readonly) BLEScales			*scales;	//体脂秤

@property (nonatomic, readonly) TreadmillMode		mode;       //跑步机当前模式
@property (nonatomic, readonly) NSInteger			value;      //跑步机倒计量
@property (nonatomic, readonly) TreadmillState		state;      //跑步机当前状态

@property (nonatomic, readonly) NSUInteger			segment;	//程式当前所在段
@property (nonatomic, readonly) TreadmillProgram	program;	//程式数据

- (void)startWithMode:(TreadmillMode)mode value:(NSInteger)value;
- (void)startWithMode:(TreadmillMode)mode value:(NSInteger)value program:(TreadmillProgram *)program;

- (void)setTargetSpeed:(CGFloat)speed incline:(NSInteger)incline;

@end
